<template>
  <div class="detail">
    <el-card class="detail-card">
      <el-button @click="goPrint" class="printbtn" type="primary" size="mini"
        >打印</el-button
      >
      <el-tabs v-model="activeName">
        <el-tab-pane label="登录账号设置" name="first" class="onetab">
          <el-form
            ref="myform"
            :model="form"
            label-width="100px"
            class="myform"
          >
            <el-form-item label="姓名:" prop="username">
              <el-input v-model.trim="form.username"></el-input>
            </el-form-item>
            <el-form-item label="密码:" prop="password">
              <el-input v-model="form.password" type="password"></el-input>
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="uploadEmpUser">提交</el-button>
              <el-button>取消</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="个人详情" name="second">
          <userInfo></userInfo>
        </el-tab-pane>
        <el-tab-pane label="岗位信息" name="third">角色管理</el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import { uploadEmpUserApi } from '../../../api/employees'
import { getStaffApi } from '../../../api/user'
import userInfo from '../component/user-info.vue'
export default {
  name: 'emplDetial',
  data() {
    return {
      activeName: 'first',
      form: {
        username: '',
        password: ''
      },
      id: this.$route.params.id,
      info: null
    }
  },
  components: {
    userInfo
  },
  methods: {
    // 跳转打印页面
    goPrint() {
      this.$router.push({
        path: '/employees/print/' + this.id,
        query: { type: this.activeName }
      })
    },
    // 更新员个人信息
    async uploadEmpUser() {
      await uploadEmpUserApi({
        ...this.info,
        ...this.form
      })
      this.$message.success('更改信息成功')
    },

    // 获取员工个人简单信息
    async getEmpUser() {
      const res = await getStaffApi(this.id)
      this.info = res
      this.form.username = res.username
    }
  },
  created() {
    this.getEmpUser()
  }
}
</script>

<style lang="scss" scoped>
.detail {
  padding: 20px;
  .el-card {
    position: relative;
    .printbtn {
      position: absolute;
      top: 20px;
      right: 20px;
      z-index: 2;
    }
    .myform {
      width: 400px;
      margin-left: 250px;
      margin-top: 50px;
    }
  }
}
</style>